package com.atguigu.lease.admin.controller.apartment;

import com.atguigu.lease.admin.service.RoomInfoService;
import com.atguigu.lease.model.bean.RoomInfo;
import com.atguigu.lease.model.dto.RoomItemQueryDto;
import com.atguigu.lease.model.dto.RoomSubmitDto;
import com.atguigu.lease.model.result.Response;
import com.atguigu.lease.model.vo.RoomDetailVo;
import com.atguigu.lease.model.vo.RoomItemVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "房间信息管理模块")
@RestController
@RequestMapping("/admin/room")
public class RoomInfoController {
    @Autowired
    RoomInfoService roomInfoService;
    @Operation(summary = "5、根据公寓id查询可租的房间列表")
    @GetMapping("listBasicByApartmentId")
    public Response<List<RoomInfo>> listBasicByApartmentId(
            @RequestParam("id") Long apartmentId
    ){
        List<RoomInfo> list = roomInfoService.listBasicByApartmentId(apartmentId);
        return  Response.ok(list);
    }


    @Operation(summary = "4、根据id删除房间数据")
    @DeleteMapping("removeById")
    public Response removeById(@RequestParam Integer id) {
        roomInfoService.removeRoomInfoById(id);
        return Response.ok(null);
    }
    @Operation(summary = "3、根据id查询房间详情")
    @GetMapping("getDetailById")
    public Response<RoomDetailVo> getDetailById(
            @RequestParam("id")Long id
    ){
        RoomDetailVo vo = roomInfoService.getDetailById(id);
        return Response.ok(vo);
    }
    @Operation(summary = "2、新增或更新房间信息")
    @PostMapping("saveOrUpdate")
    public Response saveOrUpdate(@RequestBody RoomSubmitDto roomSubmitDto) {
        roomInfoService.saveOrUpdateRoomSubmitDto(roomSubmitDto);
        return Response.ok(null);
    }

    @Operation(summary = "1、条件查询房间分页数据列表")
    @GetMapping("/pageItem")
    public Response<Page<RoomItemVo>> pageItem(RoomItemQueryDto queryDto){
        Page<RoomItemVo> page = roomInfoService.pageItem(queryDto);
        return Response.ok(page);
    }
}
